<ui:composition
  xmlns="http://www.w3.org/1999/xhtml"
  xmlns:c="http://java.sun.com/jstl/core"
  xmlns:nxu="http://nuxeo.org/nxweb/util"
  xmlns:nxh="http://nuxeo.org/nxweb/html"
  xmlns:ui="http://java.sun.com/jsf/facelets"
  xmlns:a4j="http://richfaces.org/a4j"
  xmlns:f="http://java.sun.com/jsf/core"
  xmlns:h="http://java.sun.com/jsf/html"
  xmlns:nxd="http://nuxeo.org/nxweb/document"
  xmlns:nxl="http://nuxeo.org/nxforms/layout">

<c:if test="false">
  WARN: deprecated template since 8.2, see widgets subdirectory
</c:if>


<c:if test="#{widget.mode != 'after_view' and widget.mode != 'tab_content'}">

<nxu:set var="onclick"
  value="#{nxu:test(not empty action.properties.confirmMessage, actionConfirmMessageJs, '')}#{action.confirm};#{action.properties.onclick};"
  cache="true">
<nxu:set var="tabIds"
  value="#{parentTabActionCategory}:#{action.id}"
  cache="true">
<nxu:set var="repositoryName"
  value="#{nxu:test(empty action.properties.repositoryName, widgetProperty_repositoryName, action.properties.repositoryName)}"
  cache="true">
<nxu:set var="confView"
  value="#{nxu:test(empty action.properties.view, widgetProperty_view, action.properties.view)}"
  cache="true">
<nxu:set var="finalView"
  value="#{nxu:test(empty tabWidgetView, confView, tabWidgetView)}"
  cache="true">
<nxu:set var="pattern"
  value="#{nxu:test(empty action.properties.pattern, widgetProperty_pattern, action.properties.pattern)}"
  cache="true">
<nxu:set var="finalPattern"
  value="#{nxu:test(empty tabWidgetPattern, pattern, tabWidgetPattern)}"
  cache="true">
<nxu:set var="target"
  value="#{nxu:test(empty action.properties.target, widgetProperty_target, action.properties.target)}"
  cache="true">

<c:if test="#{not useAjaxForm}">
  <nxd:restDocumentLink
    document="#{fieldOrValue}"
    repositoryName="#{repositoryName}"
    view="#{finalView}"
    pattern="#{finalPattern}"
    tabs="#{tabIds}"
    addTabInfo="false"
    accesskey="#{action.accessKey}"
    id="#{widget.id}"
    target="#{target}"
    styleClass="#{actionStyleClass} #{action.properties.styleClass}"
    onclick="#{onclick}">
    <ui:include src="/incl/action/action_icon_label_template.xhtml" />
    <ui:insert name="inside_action" />
  </nxd:restDocumentLink>
</c:if>

<c:if test="#{useAjaxForm}">

  <nxd:restDocumentLink
    document="#{fieldOrValue}"
    repositoryName="#{repositoryName}"
    view="#{finalView}"
    pattern="#{finalPattern}"
    tabs="#{tabIds}"
    addTabInfo="false"
    accesskey="#{action.accessKey}"
    id="#{widget.id}_restLink"
    resolveOnly="true"
    var="docUrl">
    <h:commandLink
      id="#{widget.id}"
      action="#{webActions.setCurrentTabIds(tabIds)}"
      onclick="if (!(jQuery(this).checkSafeEdit())){return false;};history.pushState(null, '#{tabIds}', '#{nxu:javaScriptEscape(docUrl)}');#{onclick}"
      styleClass="#{actionStyleClass} #{action.properties.styleClass}"
      accessKey="#{action.accessKey}">
      <a4j:ajax execute="@this" render="#{ajaxReRender}" />
      <ui:include src="/incl/action/action_icon_label_template.xhtml" />
      <ui:insert name="inside_action" />
    </h:commandLink>

  </nxd:restDocumentLink>

</c:if>

</nxu:set>
</nxu:set>
</nxu:set>
</nxu:set>
</nxu:set>
</nxu:set>
</nxu:set>
</nxu:set>

</c:if>

<c:if test="#{widget.mode == 'tab_content'}">
  <c:if test="#{not empty action.link}">
    <ui:include src="#{nxu:test(action.link.startsWith('/'), '', '/')}#{action.link}" />
  </c:if>
</c:if>

</ui:composition>